var PRIMARY_PATH = "";
var BASE_PATH = "";

function setPath(path,basePath){
	PRIMARY_PATH = path;
	BASE_PATH = basePath;
}

$(function() {
	// 给select2组件加载样式
	WASP_WIDGET.initializeSelectStyle();
	$(".use-select2").select2();
	// 注册清空事件
    WASP_WIDGET.registerResetClearEvent();
 	//初始化产品下拉框
    WASP_WIDGET.triggerPrdInfoSelect("prjCode");
    
    $("#assetType").change(function(){
    	$(".assetType").val($("#assetType").val());
    })
    
    $("#assetRiskmanageType").change(function(){
    	$(".assetRiskmanageType").val($("#assetRiskmanageType").val());
    })
    
    
    
    initValidateForm();
    
    var method = $("#method").val();
	if("detail" == method){
		$("#asseUnitAddForm input,select").attr("readonly","readonly");
		$("#asseUnitAddForm input,select").attr("disabled","disabled");
		$("#asseUnitAddForm input").css("cursor","default");
	}
	
	WASP_WIDGET.initializeSelectVal("prjCode",$(".prjCode").val(),$(".prjName").val());
	
	$("#assetType").val($(".assetType").val()).change();
	$("#assetRiskmanageType").val($(".assetRiskmanageType").val()).change();
});

function initValidateForm() {
	$("#asseUnitAddForm").validate({
		focusCleanup : true,
		rules : {
			'prjCode' : {
				required : true
			},
			'assetType' : {
				required : true
			},
			'assetNumber' : {
				required : true
			},
			'assetName' : {
				required : true
			},
			'assetMinQuota' : {
				required : true,
				number : true
			},
			'assetRiskmanageType' : {
				required : true
			},
			'bankAccount' : {
				required : true,
				number : true
			},
			'managementPeople' : {
				required : true
			}
		},
		messages : {
			'prjCode' : {
				required : "产品名称不能为空"
			},
			'assetType' : {
				required : "资产单元类型不能为空"
			},
			'assetNumber' : {
				required : "资产单元编号不能为空"
			},
			'assetName' : {
				required : "资产单元名称不能为空"
			},
			'assetMinQuota' : {
				required : "资产单元最低资金额度不能为空",
				number : "资产单元最低资金额度请输入数字"
					
			},
			'assetRiskmanageType' : {
				required : "资产单元风控类型不能为空"
					
			},
			'bankAccount' : {
				required : "银行账号不能为空",
				number : "银行账号请输入数字"
			},
			'managementPeople' : {
				required : "管理人不能为空"
			}
		}
	});
}

function doSubmit(){
	var form = $('#asseUnitAddForm');
	if(false === form.valid()){
		toastr.warning("请完善信息");
		return;
	}
	var method = $("#method").val();
	if("update" == method){
		$('#asseUnitAddForm').attr("action", BASE_PATH+"business/tradeStructure/updateAsseUnit.do")
	}
	
	//提交表单
	SubmitAndPreventSecond("asseUnitAddForm",true);
}